home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / wgt / dsik_c / exam2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-27  |  2.8 KB  |  89 lines

  1. /*  exam3.c - Digital Sound Interface Kit V1.01a example code
  2.  
  3.     Copyright 1993,94 Carlos Hasan
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <ctype.h>
  10. #include "sound.h"
  11. #include "ts.h"
  12.  
  13. word PeriodTable[12*4] =
  14.     /* C   C#  D   D#  E   F   F#  G   G#  A   A#  B */
  15.     { 856,808,762,720,678,640,604,570,538,508,480,453,
  16.       428,404,381,360,339,320,302,285,269,254,240,226,
  17.       214,202,190,180,170,160,151,143,135,127,120,113,
  18.       107,101,95,90,85,80,75,71,67,63,60,56 };
  19.  
  20. char KeyTable[12*3] =
  21.       "ZSXDCVGBHNJMQ2W3ER5T6Y7UI9O0P";
  22.  
  23. int main(void)
  24. {
  25.     DSMCard Card;
  26.     DSMInst *Sample;
  27.     int Key, Note, Chan;
  28.  
  29.     if (DSMLoadSetup(&Card)) {
  30.         printf("Please run SETUP.EXE to configure.\n\n");
  31.         return 1;
  32.     }
  33.     if (DSMInit(&Card)) {
  34.         printf("Error Initializing the Sound System.\n\n");
  35.         return 1;
  36.     }
  37.     if ((Sample = DSMLoadSample("DING.WAV",0L)) == NULL) {
  38.         switch (DSMStatus) {
  39.           case ERR_NORAM:  printf("Not enough system memory.\n"); break;
  40.           case ERR_NODRAM: printf("Not enough card memory.\n"); break;
  41.           case ERR_NOFILE: printf("File not found.\n"); break;
  42.           case ERR_FORMAT: printf("Invalid file format.\n"); break;
  43.           case ERR_ACCESS: printf("File damaged.\n"); break;
  44.         }
  45.         DSMDone();
  46.         return 1;
  47.     }
  48.     DSMSetupVoices(9,128);
  49.  
  50.     TSInit();
  51.     TSSetRate(70);
  52.     TSSetRoutine(DSMPoll);
  53.  
  54.     printf("\n");
  55.     printf("     C# D#    F# G# A#    C# D#    F# G# A#    C# D#   \n");
  56.     printf("  │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ \n");
  57.     printf("  │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ │ ││ ││ │ │ │ ││ │ │ \n");
  58.     printf("  │ │S││D│ │ │G││H││J│ │ │2││3│ │ │5││6││7│ │ │9││0│ │ \n");
  59.     printf("  │ └┬┘└┬┘ │ └┬┘└┬┘└┬┘ │ └┬┘└┬┘ │ └┬┘└┬┘└┬┘ │ └┬┘└┬┘ │ \n");
  60.     printf("  │ Z│ X│ C│ V│ B│ N│ M│ Q│ W│ E│ R│ T│ Y│ U│ I│ O│ P│ \n");
  61.     printf("  └──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘ \n");
  62.     printf("    C  D  E  F  G  A  B  C  D  E  F  G  A  B  C  D  E  \n");
  63.     printf("\n");
  64.     printf("   Press keys to play the sample and ESC to exit.      \n");
  65.  
  66.     Chan = 0;
  67.     while ((Key = toupper(getch())) != 27) {
  68.         for (Note = 0; Note < 12*3; Note++) {
  69.             if (Key == KeyTable[Note]) {
  70.                 /* play chord C-E-G */
  71.                 DSMPlaySample(Chan,Sample);
  72.                 DSMPlaySample(Chan+1,Sample);
  73.                 DSMPlaySample(Chan+2,Sample);
  74.                 DSMSetPeriod(Chan,PeriodTable[Note]);
  75.                 DSMSetPeriod(Chan+1,PeriodTable[Note+4]);
  76.                 DSMSetPeriod(Chan+2,PeriodTable[Note+7]);
  77.                 Chan = (Chan+3) % 9;
  78.             }
  79.         }
  80.     }
  81.  
  82.     TSDone();
  83.     TSRestoreTime();
  84.  
  85.     DSMFreeSample(Sample);
  86.     DSMDone();
  87.     return 0;
  88. }
  89.